﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.GridlistUI.model {
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import Classes.*;
    import Classes.util.*;
    import Display.aswingui.*;

    public class ItemCellModel extends GenericCellModel {

        protected var m_comObjs:Dictionary;
        protected var m_assetsToLoad:int;
        protected var m_contentLoader:Loader;

        public function ItemCellModel(){
            this.m_comObjs = new Dictionary();
            super();
        }
        override public function setCellValue(_arg1):void{
            super.setCellValue(_arg1);
            this.loadAssets();
            this.loadContent();
        }
        protected function loadAssets():void{
            this.m_assetsToLoad = 1;
            Global.delayedAssets.get(DelayedAssetLoader.MARKET_ASSETS, this.onAssetsLoaded);
        }
        protected function loadContent():void{
            var _local2:String;
            var _local1:Item = (getCellValue() as Item);
            if (_local1){
                _local2 = Global.gameSettings.getImageByName(_local1.name, "icon");
                if (((!(this.m_contentLoader)) && (_local2))){
                    this.m_contentLoader = LoadingManager.load(_local2, this.onContentLoaded, LoadingManager.PRIORITY_HIGH);
                } else {
                    this.onContentLoaded();
                };
            };
        }
        final protected function onAssetsLoaded(_arg1:DisplayObject, _arg2:String):void{
            if (_arg1){
                this.m_comObjs[_arg2] = _arg1;
                this.m_assetsToLoad--;
                if (this.m_assetsToLoad == 0){
                    this.finishLoad();
                };
            };
        }
        protected function onContentLoaded(_arg1=null):void{
            if ((getCellComponent() is IContentComponent)){
                if (((this.m_contentLoader) && (this.m_contentLoader.content))){
                    (getCellComponent() as IContentComponent).setContent(this.m_contentLoader.content);
                };
            };
        }
        protected function finishLoad():void{
            if ((getCellComponent() is IAssetComponent)){
                (getCellComponent() as IAssetComponent).makeAssets(this.m_comObjs);
            };
            this.initView();
        }
        protected function initView():void{
            var _local1:IGenericComponent = (getCellComponent() as IGenericComponent);
            if (_local1){
                _local1.build();
                _local1.updateView(getCellValue());
                addListeners();
            };
        }

    }
}//package Display.GridlistUI.model 
